<%@page import="com.remist.model.ImageMapBean"%>
<%@ page language="java" contentType="text/html; charset=utf-8"	pageEncoding="utf-8"%>
<%@include file="header.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Edit Product</title>
<script>
function setProductTypeValue(value){
	if ( value !=null && "" != value) {
		var begin = value.indexOf("#&*");
		if ( begin !=-1 ){
			var preValue = value.substring(0,begin);
			var sufValue = value.substring(begin+3,value.length);
			$("#typeName").val(sufValue);
			$("#productBean_typeId").val(preValue);
		}
	}
}

$(document).ready(function(){
	    $("table tbody tr:even").addClass("tdbgcolor1"); 
	    $("table tbody tr:odd").addClass("tdbgcolor2"); 
}
);
	function checkAndSubmit(){
		var form = document.getElementById("productUpdateForm");
 
		form.submit();
	}
</script>  
<script src="<%=contextPath %>/js/jquery_dialog.js"></script>
<link rel="stylesheet" type="text/css" href="<%=contextPath %>/js/jquery_dialog.css">
<link rel="stylesheet" type="text/css" href="<%=contextPath %>/admin/common.css">
<style>
.form-invalid {background-color:#FFFFFF;border-color:#CC3300;}
</style>
</head>
<body>
<div align="center">编辑产品</div>
<form method="post" action="productUpdate.action" id="productUpdateForm">
<table width="80%" border="0" cellpadding="3" cellspacing="1"  bgcolor="#FFFFFF" align="center">
	<tr>
		<td>选择产品类别</td>
		<td>
			<input type="text"  value="<s:property value='productBean.productType.name'/>"  name="typeName" id="typeName"/><input type="button" value="Select"  id='typeNameBtn' onclick="JqueryDialog.Open('', 'productTypeListSel.action?productTypeParenBean.parentId=<%=com.remist.common.Constant.LEVEL_ROOT %>', 300, 350,'typeNameBtn');"/>
			<input type="hidden"  name="productBean.typeId" id="productBean_typeId" value='<s:property value='productBean.typeId'/>' />
		</td>
	</tr>
	<tr>
		<td>Item Code:</td>
		<td>
		<input type="text" name="productBean.itemCode" id="itemCode" value="<s:property value='productBean.itemCode'/>" />
		</td>
	</tr>
 
	<tr>
		<td>Price:</td>
		<td><input  name="productBean.price" id="price" value="<s:property value='productBean.price'/>"/></td>
	</tr>
	<tr>
		<td>goldPrice:</td>
		<td><input  name="productBean.goldPrice" id="goldPrice" value="<s:property value='productBean.goldPrice'/>"/></td>
	</tr>
	<tr>
		<td>silverPrice:</td>
		<td><input  name="productBean.silverPrice" id="silverPrice" value="<s:property value='productBean.silverPrice'/>"/></td>
	</tr>
	<tr>
		<td>copperPrice:</td>
		<td><input  name="productBean.copperPrice" id="copperPrice" value="<s:property value='productBean.copperPrice'/>"/></td>
	</tr>
	<tr>
		<td>currentPrice:</td>
		<td><input  name="productBean.currentPrice" id="currentPrice" value="<s:property value='productBean.currentPrice'/>"/></td>
	</tr>
	
	<tr>
	<td>Material:</td>
		<td ><input  name="productBean.material" id="material" value="<s:property value='productBean.material'/>" /></td>
	</tr>	
	<tr>
	<td>weight:</td>
		<td><input  name="productBean.weight" id="weight" value="<s:property value='productBean.weight'/>"/></td>
	</tr>	
	<tr>
	<td>dimesion:</td>
		<td><input  name="productBean.dimension" id="dimension"  value="<s:property value='productBean.dimension'/>"/></td>
	</tr>
	<tr>	
	<td>Band Width:</td>
		<td><input  name="productBean.bandWidth" id="bandWidth"  value="<s:property value='productBean.bandWidth'/>"/></td>
	</tr>
	<tr>	
	<td>color:</td>
		<td ><input  name="productBean.color" id="color"  value="<s:property value='productBean.color'/>" /></td>
	</tr>
	<tr>	
		<td>Size:</td>
		<td><input  name="productBean.size" id="size"  value="<s:property value='productBean.size'/>"/></td>
	</tr>
	<tr>	
	<td>necklaceLength:</td>
		<td><input  name="productBean.necklaceLength" id="necklaceLength" value="<s:property value='productBean.necklaceLength'/>" /></td>
	</tr>
	<tr>	
	<td>description:</td>
		<td><input  name="productBean.description" id="description"  value="<s:property value='productBean.description'/>"/></td>
	</tr>
		<script>
		function showUploadWindow(id){
			var InfoW=620;
			var InfoH=400;
			var InfoUrl="../insert_images.jsp?uploadFolder=<%=com.remist.common.Constant.UPLOAD_PRODUCT %>";
			var str=window.showModalDialog(InfoUrl,"","dialogWidth="+InfoW+"px;dialogHeight="+InfoH+"px;center=yes;help=no;resizable=no;status=no;scroll=no");
			if ( str != undefined){
				addNew( str );
			}
		}	
		function addNew(value){
			var myDate=new Date();
			var millseconds = myDate.getMilliseconds();
			var table1 = $('#attachmentTable');
			$("#table的ID").find("tr").length
			/*var firstTr = table1.find('tbody>tr:first');*/
			var row = $("<tr id='"+millseconds+"'></tr>");
			var td = $("<td></td>");
 		 	var begin = value.indexOf("|");
 	 		var imageId = value.substring(begin+1,value.length);
 	 		value =  value.substring(0,begin);
			begin = value.lastIndexOf("/")+1;
			var fileName = value.substring(begin,value.length);
			td.append($("<input type='hidden' name='imagesIds' id='imagesIds' value='"+imageId+"'/><input type='hidden' name='productBean.imageUrl' value='"+value+"'><a href='#' onclick=\"viewPic('"+value+"')\">"+fileName+"</a>&nbsp;&nbsp;<a href='#' onclick='removeRow("+millseconds+")'>remove</a>")	);
			row.append(td);
			table1.append(row);
		}
		function viewPic(picPath){
			window.open("<%=contextPath %>/"+picPath, "", "", "");
		}

		function deleteImage(id){
			var sendData = {"image.id":id};
			$.ajax({
	        	type: "post",
	            url: "<%=contextPath %>/deleteImageById.action",
	            data: sendData,
	            success: function(msg){
	             /*	$("#checkFlag").html("");alert(  msg );*/ 
				}   
			}); 
		}
		function removeRow(id){
			var tr = $("#"+id );
			deleteImage( tr.find("#imagesIds").val() );
		 	tr.remove();
		}
		 
		</script>
	<tr>	
	<td  >imageUrl:</td>
		<td >
			<table width="100%" id="attachmentTable">
				<tr><td></td><td></td><td></td></tr>
				<% long missecond = System.currentTimeMillis(); %>
				<s:if test="images != null">
					<tr id="<%=missecond%>">
					<td>
					<%--
					 if ( request.getAttribute("images") != null ){
						 java.util.List<ImageMapBean> images = ( java.util.List<ImageMapBean>) request.getAttribute("images");
						 for(int i=0;i<images.size();i++){
							 System.out.println( images.get(i).getImageUrl());
						 }
					 }
					--%>
					<s:iterator value="images" status="status">
					<input type='hidden' name='imagesIds' id="imagesIds" value='<s:property value='id'/>'/>
					<input type='hidden' name='productBean.imageUrl' value='<s:property value='imageUrl'/>' />
					<a href="#" onclick="viewPic('<s:property value='imageUrl'/>')"><s:property value='imageUrl'/></a>&nbsp;&nbsp;
					<a href="#" onclick='removeRow("<%=missecond%>")'>remove</a>
					</td></tr>
					</s:iterator>
				</s:if>
			</table>
			<input type="button" value="添加照片"  onClick="showUploadWindow('pic')"/>
		
		<%--
			<input  name="productBean.imageUrl" id="imageUrl" value="<s:property value='productBean.imageUrl'/>" />
		 --%>
		</td>
	</tr>	
	<tr>
		<td colspan="2" ><input type="button" value="Save"  onclick="checkAndSubmit()"/>&nbsp;
		<input type="button" value="reset" />
		<input type="hidden" name="productBean.id" value="<s:property value='productBean.id'/>" />
			&nbsp;
			<input	type="button" value="返回"  onclick="javascript:window.history.back();" />
			</td>
</table>
</form>
</body>
</html>
